<?php

abstract class Action {
	protected $parameters;
        
    protected $types;	
    
    protected $loadError;
    
    protected $id;
    protected $name;
    protected $description;
    protected $user;
    protected $tags;
    protected $type;
    protected $dateCreated;
    protected $dateModified = NULL;
    protected $popularity;
    protected $visits;
    protected $seriesId = NULL;
    
    const Petition = "petition";
    const Survey = "survey";
    const Deliberation = "deliberation";
    const Poll = "poll";
    
    public function __construct() {    
        $this->loadError = "";
        $this->types = array(Action::Petition, Action::Survey, Action::Deliberation, Action::Poll);
    }
    
    public function load($parameters) {		
        extract($parameters);
        if (!isset($name) || strlen($name) == 0) {
            $this->loadError = "Name is not set!";
            return false;
        }
        if (!isset($description) || strlen($description) == 0) {
            $this->loadError = "Description can't be empty!";
            return false;
        }
        if (!isset($creator) || strlen($creator) == 0) {
            $this->loadError = "Creator isn't set!";
            return false;
        }
        if (!isset($type) || strlen($type) == 0) {
            $this->loadError = "Type isn't set!";
            return false;
        }
        if (!isset($tags) || strlen($tags) == 0) {
            $this->loadError = "Tags can't be empty!";
            return false;
        }	    
        if (!isset($creator) || strlen($creator) == 0) {
            $this->loadError = "User can't be empty!";
            return false;
        }	
        $this->user=$creator;
        
        if (isset($seriesid)) {
            $this->seriesId = $seriesid;
        }

        if (!in_array($type, $this->types)) {
            $this->loadError = "Invalid type!";
            return false;				
        }

        $this->name = $name;
        $this->description = $description;
        $this->user = $creator;
        $this->tags = $tags;
        $this->type = $type;

        return true;
    }
    
    public function getLoadError() {
        return $this->loadError;
    }
    
    public function getId() {
        return $this->id;
    }
    
    public function getName() {
        return $this->name;
    }
    
    public function setName($name) {
        $this->name=$name;
    }
    
    public function getDescription() {
        return $this->description;
    }
    
    public function setId($id) {
        $this->id = $id;
    }    
    
    public function setDescription($description) {
        $this->description=$description;
    }
    
    public function getUser() {
        return $this->user;
    }
    
    public function setUser($user) {
        $this->user=$user;
    }
    
    public function getTags() {
        return $this->tags;
    }
    
    public function setTags($tags) {
        $this->tags=$tags;
    }
    
    public function getType() {
        return $this->type;
    }
    
    public function setType($type) {
        $this->type=$type;
    }
    
    public function getDateCreated() {
        return $this->dateCreated;
    }
    
    public function setDateCreated($dateCreated) {
        $this->dateCreated=$dateCreated;
    }
    
    public function getDateModified() {
        return $this->dateModified;
    }
    
    public function setDateModified($dateModified) {
        $this->dateModified=$dateModified;
    }
    
    public function getPopularity() {
        return $this->popularity;
    }
    
    public function setPopularity($popularity) {
        $this->popularity=$popularity;
    }
    
    public function getVisits() {
        return $this->visits;
    }
    
    public function setVisits($visits) {
        $this->visits=$visits;
    }
    
    public function setSeriesId($seriesId) {
        $this->seriesId = $seriesId;
    }     
    
    public function getSeriesId() {
        return $this->seriesId;
    }    
        
    public function getJsonArray() {
        return array( "id" => $this->id,
                     "type" => $this->type,
                     "name" => $this->name,
                     "description" => $this->description,
                     "userName" => $this->user,
                     "dateCreated" => date("d-m-Y H:i:s", $this->dateCreated),
                     "dateModified" => $this->dateModified != NULL ? date("d-m-Y H:i:s", $this->dateModified) : '',
                     "tags" => $this->tags,
                     "popularity" => $this->popularity,
                     "visits" => $this->visits,
                     "seriesid" => $this->seriesId
        );
    }
    
}

?>